package com.weishuang.account.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.weishuang.account.entity.RolePerm;
import com.weishuang.account.mapper.RolePermMapper;
import com.weishuang.account.service.RolePermService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@Service
public class RolePermServiceImpl extends ServiceImpl<RolePermMapper, RolePerm> implements RolePermService {

    @Autowired
    private RolePermMapper rolePermMapper;

    @Override
    public List<RolePerm> getByRoleId(String roleId) {
        LambdaQueryWrapper<RolePerm> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(RolePerm::getRoleId, roleId);
        return rolePermMapper.selectList(queryWrapper);
    }

    @Override
    public List<RolePerm> getByRoleIds(Collection<String> roleIds) {
        if(CollectionUtils.isEmpty(roleIds)){
            return new ArrayList<>();
        }
        LambdaQueryWrapper<RolePerm> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(RolePerm::getRoleId, roleIds);
        return rolePermMapper.selectList(queryWrapper);
    }
}
